//
//  DataSaveUtils.m
//  Traffic
//
//  Created by CruItaly on 2017/11/2.
//  Copyright © 2017年 com.infohold.cn. All rights reserved.
//

#import "DataSaveUtils.h"
#import "FileManager.h"
@implementation DataSaveUtils

+ (void)saveUserInfo:(UserInfoBean *) userinfo{
    [FileManager writeFile:userinfo filePath:UserPath fileName:@"userInfo"];
}
+ (UserInfoBean *)getUserInfo{
    UserInfoBean *obj = [FileManager readFilePath:UserPath fileName:@"userInfo" className:nil];
    return obj;
}
+ (void)clearUserInfo{
    [FileManager removeFilePath:UserPath fileName:@"userInfo"];
}




//保存集合数据
+ (BOOL)saveNsArray:(NSArray *)array name:(NSString *)name{
    NSString *filePath= [CachesDirPath stringByAppendingString:name];
    return [NSKeyedArchiver archiveRootObject:array toFile:filePath];
}
+ (NSArray*)getNSArrayByName:(NSString *)name{
    NSString *filePath = [CachesDirPath stringByAppendingString:name];
    NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
    return arr;
}
//使用
//NSArray *arr = [NSArray arrayWithObjects:@1,@"你好",@3,p,nil];
//BOOL b =[DataSaveUtils saveNsArray:arr name:@"textArray"];
//if (b) {
//    NSLog(@"归档成功");
//}
//
////对象解档
//NSArray *arr2 = [DataSaveUtils getNSArrayByName:@"textArray"];
//for (NSString *str in arr2) {
//    NSLog(@"%@",str);
//}

//保存简单基本信息，或配置信息
+ (void)saveUserName:(NSString *)name{
    [[NSUserDefaults standardUserDefaults] setValue:name forKey:@"NSUserDefaults_userName"];
}
+ (NSString *)getUserName{
    return [[NSUserDefaults standardUserDefaults] valueForKey:@"NSUserDefaults_userName"];
}

+ (void)saveToken:(NSString *)token{
    [[NSUserDefaults standardUserDefaults] setValue:token forKey:@"NSUserDefaults_token"];
}

+ (NSString *)getToken{
    return [[NSUserDefaults standardUserDefaults] valueForKey:@"NSUserDefaults_token"];
}



+ (void)saveBgCode:(NSString *)bgcode{
    [[NSUserDefaults standardUserDefaults] setValue:bgcode forKey:@"NSUserDefaults_bgcode"];
}
+ (NSString *)getBgCode{
     return [[NSUserDefaults standardUserDefaults] valueForKey:@"NSUserDefaults_bgcode"];
}

+ (void)saveLocationInfo:(MyPoint *)locationInfo{
      [FileManager writeFile:locationInfo filePath:UserPath fileName:@"locationInfo"];
}
+ (MyPoint*)getLocationInfo{
      MyPoint *obj = [FileManager readFilePath:UserPath fileName:@"locationInfo" className:nil];
    return obj;
}






@end
